package org.vectrics.recruiter.job;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.vectrics.common.db.JdbcTarget;
import org.vectrics.common.db.ProcessException;




public class FindJobIdsForCandidateJdbc implements JdbcTarget {
	private transient static Logger log = Logger.getLogger(FindJobIdsForCandidateJdbc.class);
	private static SimpleDateFormat sqlDateFormat = new SimpleDateFormat("yyyy-MM-dd");
	
	private String queryStr = "";
	private Vector jobSet = new Vector();		

	public FindJobIdsForCandidateJdbc(Long candidateId) {         
		log.debug("FindUsersWithRoleJdbc() - constructing query");
		String orderClause = " order by j.date_posted";
		String whereClause = "";
		whereClause += " where";
		whereClause += " (j.uid = jc.job_id) and (jc.user_id = " +	candidateId.toString() + ")";            
        
		queryStr = "select distinct j.uid as job_id"
				+ " from job_post j, job_candidate jc" 
				+ whereClause 
				+ orderClause;

		if (log.isDebugEnabled()) {
			log.debug("FindJobIdsForCandidateJdbc() - queryStr = " + queryStr);
		}
	}
	

	public List getJobSet() {
		return(jobSet);
	}
	
	public void processResults(ResultSet results) throws ProcessException {
		try {
			while (results.next()) {
				Long jobId = new Long(results.getLong("job_id"));
				jobSet.add(jobId);
			}
		}
		catch (java.sql.SQLException se) {
			log.error("getUsersWithRole() - SQL Exception while processing results list", se);
		}
	}

	
	public String getQuery() {
		return(queryStr);		
	}
}

